package org.simplecrm.service.customer;

import org.simplecrm.domain.customer.Customer;
import org.simplecrm.repository.customer.CustomerDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 */
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerDAO customerDAO;

    @Override
    @Transactional
    public List<Customer> getAllCustomers() {

        List res;
        res = customerDAO.getAllCustomers();
        return res;
    }

    @Override
    @Transactional
    public List<Customer> getCustomersPage(int pageNumber, int pageSize) {


        List res;
        res = customerDAO.getCustomersPage(pageNumber, pageSize);
        return res;
    }

    @Override
    @Transactional
    public Long getCustomersCount() {

        Long res;
        res = customerDAO.getCustomersCount();
        return res;
    }

    @Override
    @Transactional
    public void deleteCustomer(int id) {
        customerDAO.deleteCustomer(id);
    }

    @Override
    @Transactional
    public Customer getCustomerById(int id) {

        Customer res = null;
        res = customerDAO.getCustomerById(id);
        return res;
    }

    @Override
    @Transactional
    public void addNewCustomer(Customer newCustomer) {
        customerDAO.addNewCustomer(newCustomer);
    }

    @Override
    @Transactional
    public void updateCustomer(Customer changedCustomer) {
        customerDAO.updateCustomer(changedCustomer);
    }
}
